import { adminLogin} from './../../api/admin'
import * as types from './../actionTypes'
const userAction = (values)=>{
    return (dispatch) =>{
        return new Promise(resolve =>{ //将后续的业务逻辑交给组件
            adminLogin(values).then(res=>{
                console.log('res',res)
                //修改状态
                dispatch({
                    type:types.CHANGE_ADMIN_NAME,
                    payload:res.data.data.adminname
                })
                dispatch({
                    type:types.CHANGE_LOGIN_STATE,
                    payload:true,
                })
                dispatch({
                    type:types.CHANGE_ROLE,
                    payload:res.data.data.role
                })
                dispatch({
                    type:types.CHANGE_TOKEN,
                    payload:res.data.data.token
                })
                dispatch({
                    type:types.CHANGE_TRUE_NAME,
                    payload:res.data.data.truename
                })
                resolve(res)
            })

        })
    }
}

export default userAction